package ${service.packageName}.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import ${service.pojoClass};
import ${service.daoClass};
import java.util.List;
import java.util.Objects;
import org.apache.commons.lang3.StringUtils;
import ${service.packageName}.${service.interfaceClassName};
<#list service.importNames as data>
import ${data};
</#list>
/**
*
* @author wuxi
*/
@Service
public class ${service.className} implements ${service.interfaceClassName}{

    @Resource
    private ${service.daoClassName} ${service.daoName};

    @Override
    public ${service.pojoName} selectOne(${service.pojoName} po){
        LambdaQueryWrapper<${service.pojoName}> queryWrapper = getQueryWrapper(po);
        return ${service.daoName}.selectOne(queryWrapper);
    }

    @Override
    public List<${service.pojoName}> selectList(${service.pojoName} po){
        LambdaQueryWrapper<${service.pojoName}> queryWrapper = getQueryWrapper(po);
        return ${service.daoName}.selectList(queryWrapper);
    }

    private LambdaQueryWrapper<${service.pojoName}> getQueryWrapper(${service.pojoName} po){
        LambdaQueryWrapper<${service.pojoName}> queryWrapper = new LambdaQueryWrapper<>();
        <#list service.pojoAttr as attr>
            <#if (attr.type == "String")>
        if(StringUtils.isNotBlank(po.${toGet(attr.name)}())){
           queryWrapper.eq(${service.pojoName}::${toGet(attr.name)},po.${toGet(attr.name)}());
        }
            <#else>
        if(Objects.nonNull(po.${toGet(attr.name)}())){
            queryWrapper.eq(${service.pojoName}::${toGet(attr.name)},po.${toGet(attr.name)}());
        }
            </#if>
        </#list>
        return queryWrapper;
    }
}